<!doctype html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/style.css" />		
		<script type="text/javascript" src="../js/head_public.js" ></script>
		<style>
			.jilu-money{font-size: 18px;color: #ff7e00;}
			.jifen-number{font-size: 14px;color: #323232;}
			.zhichu{color: #323232;font-size: 14px;}
			.zhichu span{color: #666666;}
			.jifen-list li{border-bottom: 1px solid #EEEEEE;background: #fff;}
			.type-btn{overflow: hidden;height: 40px;margin-bottom: 8px;}
			.type-btn h1:nth-of-type(1){border-right: 1px solid #d26b07;}
			.type-btn h1{width: 50%;float: left;background: #fff;font-size: 16px;text-align: center;font-weight: normal;height: 40px;line-height: 40px;margin: 0px;}
		    .type-btn-active{border-bottom: 2px solid #ef7a08;color: #ef7a08;font-weight: bold!important;}
		    .guzh1{overflow: hidden;}
			.guzh1 button{display: block;float: left;width: 25%;margin: 9px;height: 0.6rem;color: #fff;border: none;border-radius: 0.3rem;padding: 0px!important;}
		</style>
	</head>
	<body>
		<header class="mui-bar mui-bar-nav ding-bar">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		    <h1 class="mui-title">电梯充值记录</h1>
		</header>
		<div class="mui-content">
			<div class="type-btn">
				<h1 class="type-btn-active" type="1">已付款</h1>
				<h1 type="-1">待付款</h1>
			</div>
			
			<ul class="jifen-list" id="list">
				<!--<li>
					<div class="mui-row">
						<div class="mui-col-xs-6 jilu-money" >￥200</div>
					    <div class="mui-col-xs-6 jifen-number " style="text-align: right;">2019-12-12</div>
					</div>
					<div class="mui-row">
						<div class="mui-col-xs-5 jifen-number ">季度缴费</div>
					    <div class="mui-col-xs-7 zhichu " style="text-align: right;"><span>电梯编号：</span>HHH124645</div>
					</div>
				</li>-->
				
			</ul>
		
		</div>
		<script src="../js/mui.min.js"></script>
		<script src="../js/jquery-1.8.0.min.js"></script>
		<script src="../js/common.js"></script>
		<script src="../js/session.js"></script>
		<script type="text/javascript">
			mui(".geren-list").on("tap","a[data-href]",function(){
				mui.openWindow({url:$(this).attr("data-href")})
			})
			var wxChannel = null; // 微信支付
			var aliChannel = null; // 支付宝支付
			var channel = null;
			//页面加载时
			//页面加载时
			mui.plusReady(function(){
				//关闭等待框
				plus.nativeUI.closeWaiting();
				plus.payment.getChannels(function(channels){
					for  (var  i  in  channels)  {
			            if  (channels[i].id  ==  "wxpay")  {
			                    wxChannel  =  channels[i];
			            }  else  {
			                    aliChannel  =  channels[i];
			            }
			        }
			    },function(e){
			        alert("获取支付通道失败："+e.message);
			    });
		   });
		   //		 检测是否安装支付服务
			function checkServices(pc){
				if(!pc.serviceReady){
					var txt=null;
					switch(pc.id){
						case 'alipay':
						txt='检测到系统未安装“支付宝快捷支付服务”，无法完成支付操作，是否立即安装？';
						break;
						default:
						txt='系统未安装“'+pc.description+'”服务，无法完成支付，是否立即安装？';
						break;
					}
					plus.nativeUI.confirm(txt, function(e){
						if(e.index==0){
							pc.installService();
						}
					}, pc.description);
				}
			}
			$(function(){
				var userid=getCookie("userid");
				if(userid==null||userid==""){
					alert("您还没有登录，请先登录")
					location.href="../public/login.html"
				}else{
					getfinished(userid,"1")
					mui(".type-btn").on("tap","h1",function(index){
						$("#list").empty()
						var type=$(this).attr("type");
						$(this).addClass("type-btn-active").siblings("h1").removeClass("type-btn-active");
						if(type=="1"){
							getfinished(userid,type)
						}else if(type=="-1"){
							getWillfinish(userid,type)
						}
					})
				}
			})
//			读取已完成的
			function getfinished(userid,type){
				var param={};
				param.member_id=userid;
				param.type=type;
				$.post(net+"/public/index.php?s=api/Predeposit/pdrecharge/",param,function(res){
					if(res.code=="1002"){
						alert(res.message);
					}else if(res.code=="200"){
						if(res.result!=""&&res.result!=null){
							var str="";
							$.each(res.result,function(index,val){
								var time=timestampToTime1(this.pdr_addtime)
								var zhifu_type="";
								if(this.pdr_payment_code=="alipay_app"){
									zhifu_type="支付宝支付"
								}else if(this.pdr_payment_code=="wxpay_app"){
									zhifu_type="微信支付"
								}
             	   	  	 	str+='<div class="gongdan-con"><ul class="gongdan-ul"><li><span>订单编号：</span><span>'+this.pdr_sn+'</span></li>'
		    	               +'<li><span>电梯编号：</span><span>'+this.pdr_ecode+'</span></li><li><span>下单时间：</span><span>'+time+'</span></li><li><span>缴费类型：</span><span>'+this.lg_type+'</span></li>'
		    		           +'<li style="position: relative;"><span>支付金额：</span><span style="color:red">￥'+this.pdr_amount+'</span></li>'
		    		           +'<li style="border:none"><span>支付方式：</span><span>'+zhifu_type+'</span></li></ul></div>'
		    		           
             	   	  	    })
             	   	  	    $("#list").append(str)
						}
					}
				})
			}
			//			读取未完成的
			function getWillfinish(userid,type){
				var param={};
				param.member_id=userid;
				param.type=type;
			
			 
				$.post(net+"/public/index.php?s=api/Predeposit/pdrecharge/",param,function(res){
					if(res.code=="1002"){
						alert(res.message);
					}else if(res.code=="200"){
						if(res.result!=""&&res.result!=null){
							var str="";
							$.each(res.result,function(index,val){
								var time=timestampToTime1(this.pdr_addtime)
								var zhifu_type="";
								if(this.pdr_payment_code=="alipay_app"){
									zhifu_type="支付宝支付"
								}else if(this.pdr_payment_code=="wxpay_app"){
									zhifu_type="微信支付"
								}
             	   	  	 	str+='<div class="gongdan-con"><ul class="gongdan-ul"><li><span>订单编号：</span><span>'+this.pdr_sn+'</span></li>'
		    	               +'<li><span>电梯编号：</span><span>'+this.pdr_ecode+'</span></li><li><span>下单时间：</span><span>'+time+'</span></li><li><span>缴费类型：</span><span>'+this.lg_type+'</span></li>'
		    		           +'<li style="position: relative;"><span>支付金额：</span><span style="color:red">￥'+this.pdr_amount+'</span></li>'
		    		           +'<li><span>支付方式：</span><span>'+zhifu_type+'</span></li></ul>'
		    		           +'<div class="guzh1">'
		    		           +'<button class="gzx quxiao" data-id="'+this.pdr_id+'" style="background:#ff7e00" >取消订单</button><button class="gzx go_pay" data-id="'+this.pdr_id+'" pdr_sn="'+this.pdr_sn+'" payment_code="'+this.pdr_payment_code+'">支付订单</button></div></div>'
             	   	  	 })
             	   	  	 $("#list").append(str);
             	   	  	 //取消订单
             	   	  	 mui("#list").on("tap",".quxiao",function(){
             	   	  	 	
							var id=$(this).attr("data-id");
							if(id==""||id==null){
								alert("网页出错");
								return false;
							}
							$.post(net+"/public/index.php?s=api/Predeposit/chanel_pdrecharge",{"member_id":userid,"id":id},function(res){
								if(res.code=="200"){
									location.reload();
								}
							})
						})
             	   	  	 //去支付
             	   	  	  mui("#list").on("tap",".go_pay",function(){
             	   	  	  	var id=$(this).attr("data-id");
             	   	  	  	var pdr_sn=$(this).attr("pdr_sn")
             	   	  	  	var payment_code=$(this).attr("payment_code");
             	   	  	  	 
             	   	  	  	    if(payment_code=="alipay_app"){
									channel=aliChannel;
								}else if(payment_code=="wxpay_app"){
									
									channel=wxChannel;
								}
             	   	  	  	  $.post(net+"/public/index.php?s=api/payment/pd_order",{"member_id":userid,"pay_sn":pdr_sn,"payment_code":payment_code},function(res){
								if(res.code=="200"){
									plus.nativeUI.closeWaiting();		
	       				
							      	checkServices(channel)
							      
							        plus.payment.request(channel, res.result, function(result) {
	                                    location.href="index.html"
							        }, function(e) {
							        	
							        	alert("支付失败")
							        });   	
								}
								
							  })
             	   	  	  })
						}
					}
				})
			}
			
		</script>
	</body>
</html>